Skip to content

9src/cc: pcc produces $O.out, keeps .6 objects; use basename for prog…#135

Merged
staalmannen merged 1 commit into
mainfrom
claude/upgrade-ape-c-library-mmZGd
May 21, 2026
Merged

9src/cc: pcc produces $O.out, keeps .6 objects; use basename for prog…#135
staalmannen merged 1 commit into
mainfrom
claude/upgrade-ape-c-library-mmZGd

Conversation

@staalmannen

Copy link
Copy Markdown
Owner

… detection

  • Use basename of argv[0] (strip path prefix) so /amd64/bin/ape/pcc is detected as "pcc" correctly
  • pcc output: smprint("%s.out", ot->o) e.g. "6.out" — matches Plan9 6l default and what mkmany expects
  • pcc keeps .6 object files after linking (Plan9 native convention); only cc mode removes the intermediate .o (APE configure-compat mode)

https://claude.ai/code/session_01WGAwvvTwDg2yknFkmZ3qzs

… detection

- Use basename of argv[0] (strip path prefix) so /amd64/bin/ape/pcc is
  detected as "pcc" correctly
- pcc output: smprint("%s.out", ot->o) e.g. "6.out" — matches Plan9 6l default
  and what mkmany expects
- pcc keeps .6 object files after linking (Plan9 native convention);
  only cc mode removes the intermediate .o (APE configure-compat mode)

https://claude.ai/code/session_01WGAwvvTwDg2yknFkmZ3qzs
@staalmannen staalmannen merged commit 223cb5a into main May 21, 2026
1 check passed

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modifies the compiler wrapper to distinguish between POSIX mode (cc) and Plan 9 native mode (pcc) by inspecting the program name. It adjusts the default output filename and object extension accordingly, and restricts intermediate file cleanup to POSIX mode. Review feedback identifies a potential null pointer dereference if the argument list is empty and suggests consolidating redundant string comparisons while adding necessary error handling for memory allocation in the pcc mode path.

Comment thread sys/src/ape/9src/cc.c
Comment on lines +70 to +71
prog = utfrrune(argv[0], '/');
prog = prog ? prog+1 : argv[0];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If argc is 0, argv[0] will be NULL, causing utfrrune to dereference a null pointer and crash. While argc is usually at least 1 in standard execution environments, adding a check for argv[0] or argc before processing the program name is a safer practice to ensure robustness.

Comment thread sys/src/ape/9src/cc.c
Comment on lines +74 to +75
objext = (strcmp(prog, "cc") == 0) ? "o" : ot->o;
oname = (strcmp(prog, "cc") == 0) ? "a.out" : smprint("%s.out", ot->o);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The strcmp(prog, "cc") check is performed twice. Consolidating this into an if-else block would improve readability and avoid redundant string comparisons. Additionally, smprint can return NULL if memory allocation fails; its return value should be checked to prevent a potential null pointer dereference later when oname is used.

	if(strcmp(prog, "cc") == 0){
		objext = "o";
		oname = "a.out";
	}else{
		objext = ot->o;
		if((oname = smprint("%s.out", ot->o)) == NULL){
			fprint(2, "out of memory\n");
			exits("mem");
		}
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants